<?php
	defined('_JEXEC') or die(); 
    JHTML::_('behavior.tooltip'); 
?>
<style>
    #tbl_filter{
        margin: 0 ; padding: 0 ;
    }
    #tbl_filter td{
        padding: 3px;
    }
    #tbl_filter input, #tbl_filter img {
        float: left;
        margin: 0 5px 0 0;
        width: auto;
    }
    #extra_filter_field { width: 114px; }
    table.adminlist tbody tr td { padding: 8px 8px; }
    table.adminlist thead th { padding: 8px; }
</style>
<link rel="stylesheet" type="text/css" href="<?php echo JURI::root(); ?>js/multiselect/jquery.multiselect.css" />
<link rel="stylesheet" type="text/css" href="<?php echo JURI::root(); ?>js/multiselect/jquery-ui.css" />
<script type="text/javascript" src="<?php echo JURI::root(); ?>js/jquery.js"></script>
<script type="text/javascript" src="<?php echo JURI::root(); ?>js/jquery-ui.min.js"></script>
<script type="text/javascript" src="<?php echo JURI::root(); ?>js/multiselect/jquery.multiselect.js"></script>
<script>
jQuery(function(){
		var status = <?php echo isset($this->status)?$this->status:2;?>;
		jQuery(".status").val(status);
		
		var status = <?php echo isset($this->status)?$this->status:1;?>;
		jQuery(".status").val(status);
		
		var topDisplay = <?php echo empty($this->topDisplay)?20:$this->topDisplay;?>;
		jQuery("#topDisplaySelect").val(topDisplay);	
		
});
</script>
<div class="row-fluid">
    <?php if (!empty( $this->sidebar)) : ?>
	<div id="j-sidebar-container" class="span2">
		<?php echo $this->sidebar; ?>
	</div>
	<div id="j-main-container" class="span10">
	<?php else : ?>
		<div id="j-main-container">
	<?php endif;?>
		<br clear="all">	
    	<div class="alert">
             <form action="<?php echo JRoute::_("index.php?option=com_wrd&controller=reports")?>" method="post" name="filterform" >
                <table style='margin-bottom:5px' id="tbl_filter">
					<tr>
						<td>Status:<br>
							<select class="status" name="status" id="status">
								<option value="-1">All</option>
								<option value="1">Approve</option>
								<option value="0">Waiting Approve</option>
								<option value="9">Cancel</option>
							</select>
						</td>
						<td>Redemption date, from<br>
							<?php
								echo JHTML::_ ( 'calendar', $this->pr['date_from'], 'date_from', 'date_from', '%Y-%m-%d' );
							?>
						</td>
					
						
						<td>To:<br>
							<?php
								echo JHTML::_ ( 'calendar', $this->pr['date_to'], 'date_to', 'date_to', '%Y-%m-%d' );
							?>
						</td>
                       
						  </tr>
						  <tr>
						  	<td align="left" valign="top" style="">
								Choose: <br>
							   <select class="topDisplay" name="topDisplaySelect" id="topDisplaySelect">
									<option value="5">5</option>
									<option value="10">10</option>
									<option value="15">15</option>
									<option value="20">20</option>
									<option value="30">30</option>
									<option value="50">50</option>
									<option value="100">100</option>
									<option value="">All</option>
								</select>
						   	</td>
						   	<td>
								<input type="submit" name="view" onclick="document.getElementById('submitViewExcel').value = 'submitViewExcel';  document.getElementById('task').value = 'redempreport';" value="View" />	
								<input type="submit" name="exportexcel" onclick="document.getElementById('submitViewExcel').value = 'submitViewExcel';document.getElementById('task').value = 'exredempreport';" value="Export to excel" />						   
							</td> 
						  </tr>
                </table>
                <input type="hidden" name="controller" value="reports" />
                <input type="hidden" name="option" value="com_wrd" />
                <input type="hidden" name="submitViewExcel" id="submitViewExcel" value="" />
				<input type="hidden" name="task" id="task" value="" />
				</form>    
         </div>
<form id="adminForm" action="<?php echo JRoute::_("index.php?option=com_wrd")?>" method="post" name="adminForm" >			
<style>
.extra-adminlist strong { color:#025A8D; font-size: 1.2em; font-weight: bold; }
table.extra-adminlist .extra-adminlist-tr td {background: #F7F7F7; }
.filter-detail { border-top: 1px solid #CCC; padding-bottom: 3px; font-size: 1.4em; }
.filter-detail span { color: #e72222; }
</style>
<h3 class="filter-detail"><br/><span style="color:#C00; float:right;">Total: <?php echo $this->pagination->total; ?></span></h3>
<table class="adminlist extra-adminlist table">
  <thead>
    <tr class="extra-adminlist-tr" >
        <th nowrap="nowrap"><strong>No</strong></th>                   
		<th><strong>Item</strong></th>
		<th><strong>Created Date</strong></th>		
		<th><strong>Redeemption Code</strong></th>
		<th><strong>Voucher Code</strong></th>	
		<th><strong>Expired</strong></th>			
		<th><strong>Date Use voucher</strong></th>
		<th><strong>Outlet Use voucher</strong></th>
		<!--<th><strong>Member ID</strong></th>-->
		<th><strong>Name</strong></th>
		<th><strong>Point Redemp</strong></th>
		<th><strong>Cash Redemp</strong></th>
		<th><strong>Retail Pricing</strong></th>
		<th><strong>Cost Pricing</strong></th>
	
	    <th nowrap="nowrap"><strong>Status Redemption</strong></th> 
    </tr>
  </thead>
  <tbody>
    <?php 
	// echo '<pre>';print_r($this->items); /******** Get Redemption Ids ********/
     ?>
    <?php 
        if(!empty($this->items)):
            $index = 0;
            $i=1;
            //echo '<pre>'; print_r($this->items);
			foreach($this->items as $key => $item):
            	$item->productName = unserialize($item->productName);
            	
				$item->productName = $item->productName['en-GB'];
               $bg = $i%2;
                echo '<tr style="cursor: pointer;" class="row'.($bg).'" valign="top">';
                    echo '<td  style="width: 5%;">'.$i.'</td>';   
					echo '<td  style="width:30%">'.$item->productName.'</td>'; 
					echo '<td  style="width:20%">'.(strtotime($item->exchange_date) ? date("d-m-Y H:i:s",strtotime($item->exchange_date)) : "") .'</td>'; 
					echo '<td style="text-align:right;width:8%;">'.$item->code_redemption.'</td>';
					echo '<td style="text-align:right;width:8%;">'.$item->code_voucher.'</td>';
					echo '<td style="text-align:right;width:8%;">';
						echo empty($item->expired)? '':date("d-m-Y",strtotime($item->expired));
					echo '</td>';
					echo '<td style="text-align:right;width: 8%;">'.$item->date_voucher .'</td>';
					echo '<td style="text-align:right; width: 15%;">'.$item->outlet_name_use_voucher .'</td>';
					//echo '<td style="text-align:right;width: 5%;">'.$item->member_id .'</td>';
					echo '<td style="text-align:right;width: 12%;">'.$item->l_name . " ".$item->f_name .'</td>';
					echo '<td style="text-align:right;width: 8%;">'.number_format($item->point,0,".",",") .'</td>';
					echo '<td style="text-align:right;width: 8%;">'.number_format($item->cash,0,".",",") .'</td>';
					echo '<td style="text-align:right;width: 8%;">'.number_format($item->product_cost,0,".",",") .'</td>';
					echo '<td style="text-align:right;width:8%;">'.number_format($item->cost_pricing,0,".",",") .'</td>';
					
					echo '<td  style="width: 5%;">';
					//echo $item->status;
					if($item->approved == 0){
						echo "Waiting Approve";
					}
					elseif($item->approved==1){ echo "Approve";}
					elseif($item->approved==9){echo "Cancel";}
					echo '</td>';
                echo '</tr>';
                
               $i++;
                
            endforeach;
        endif;
    ?>
    
  </tbody>
  <tfoot>
        <tr>
            <td colspan="16">
                <?php
                     echo $this->pagination->getListFooter();
                ?>
            </td>
        </tr>
    </tfoot>
</table>
                <input type="hidden" name="controller" value="reports" />
                <input type="hidden" name="option" value="com_wrd" />
				<input type="hidden" name="topDisplaySelect" id="topDisplay" value="" />
				<input name="status" type="hidden" class="status" value="" />
                <input type="hidden" name="task" value="redempreport" />
                <input type="hidden" name="boxchecked" value="0" />
                <?php echo JHTML::_( 'form.token' ); ?>
            </form>
        </div>
        
</div>
